Class AttachableNode
This component is used in conjunction with AttachableBehaviour and is used to denote a specific child GameObject that an AttachableBehaviour can attach itself to.
Inherited Members
Namespace: Global Namespace
Assembly: Unity.Netcode.Runtime.dll
Syntax
public class AttachableNode : NetworkBehaviour
Remarks
Primarily, the AttachableNode can be used as it is or can be extended to perform additional logical operations when something attaches to or detaches from the AttachableNode instance.
Fields
DetachOnDespawn
When enabled, any attached AttachableBehaviours will be automatically detached and re-parented under its original parent.
Declaration
public bool DetachOnDespawn
Field Value
Type | Description |
---|---|
bool |
m_AttachedBehaviours
A List<T> of the currently attached AttachableBehaviours.
Declaration
protected readonly List<AttachableBehaviour> m_AttachedBehaviours
Field Value
Type | Description |
---|---|
List<AttachableBehaviour> |
Properties
HasAttachments
Returns true if the AttachableNode instance has one or more attached AttachableBehaviour components.
Declaration
public bool HasAttachments { get; }
Property Value
Type | Description |
---|---|
bool |
Methods
OnAttached(AttachableBehaviour)
Override this method to be notified when an AttachableBehaviour has attached to this node.
Declaration
protected virtual void OnAttached(AttachableBehaviour attachableBehaviour)
Parameters
Type | Name | Description |
---|---|---|
AttachableBehaviour | attachableBehaviour | The AttachableBehaviour that has been attached. |
OnDetached(AttachableBehaviour)
Override this method to be notified when an AttachableBehaviour has detached from this node.
Declaration
protected virtual void OnDetached(AttachableBehaviour attachableBehaviour)
Parameters
Type | Name | Description |
---|---|---|
AttachableBehaviour | attachableBehaviour | The AttachableBehaviour that has been detached. |
OnNetworkPreDespawn()
Gets called before OnNetworkDespawn() has been invoked for all NetworkBehaviours associated with the currently spawned NetworkObject instance.
Declaration
public override void OnNetworkPreDespawn()
Overrides
Remarks
If the NetworkObject this AttachableNode belongs to is despawned, then any attached AttachableBehaviour will be detached during OnNetworkDespawn.
OnNetworkPreSpawn(ref NetworkManager)
Gets called after the NetworkObject is spawned. No NetworkBehaviours associated with the NetworkObject will have had OnNetworkSpawn() invoked yet.
A reference to NetworkManager is passed in as a parameter to determine the context of execution (IsServer
or IsClient
).
Declaration
protected override void OnNetworkPreSpawn(ref NetworkManager networkManager)
Parameters
Type | Name | Description |
---|---|---|
NetworkManager | networkManager | a ref to the NetworkManager since this is not yet set on the NetworkBehaviour |
Overrides
Remarks
The NetworkBehaviour will not have anything assigned to it at this point in time. Settings like ownership, NetworkBehaviourId, NetworkManager, and most other spawn-related properties will not be set. This can be used to handle things like initializing a NetworkVariable.
OnOwnershipChanged(ulong, ulong)
Invoked on all clients. Override this method to be notified of any ownership changes (even if the instance was neither the previous or newly assigned current owner).
Declaration
protected override void OnOwnershipChanged(ulong previous, ulong current)
Parameters
Type | Name | Description |
---|---|---|
ulong | previous | the previous owner |
ulong | current | the current owner |
Overrides
Remarks
When the ownership of an AttachableNode changes, it will find all currently attached AttachableBehaviour components that are registered as being attached to this instance.